package cn.example.interpector;

import cn.example.configure.CustomerPropertis;
import cn.example.util.ToolFactory;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 全局拦截获取根路径
 * Created by WuYubin on 2016/6/17.
 */
public class GlobalInterceptor extends HandlerInterceptorAdapter {

    private static final String HY_DOMAIN = "HY_DOMAIN";
    @Resource
    private CustomerPropertis customerPropertis;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println(customerPropertis.getMessage());
        String domain = ToolFactory.getHttpUtil().getProjectHost(request);
        request.setAttribute(HY_DOMAIN, domain);
        Object attr = request.getSession().getAttribute(HY_DOMAIN);
        if (attr == null) {
            request.getSession().setAttribute(HY_DOMAIN, domain);
        }
        return super.preHandle(request, response, handler);
    }

}
